//
//  CityGuide.m
//  LStyle
//
//  Created by Obaid Abdul Maroof on 12/19/09.
//  Copyright 2009 Vrije University. All rights reserved.
//

#import "CityGuide.h"


@implementation CityGuide

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

	lstView = [[ListView alloc] initWithNibName:@"ListView" bundle:[NSBundle mainBundle]];
	
	tvPictures.separatorStyle = UITableViewCellSeparatorStyleNone;
	self.createFooter;
	tcPictures = [[UITabBar alloc] initWithFrame:CGRectMake(0, 480-50, 320, 30)];
	
	[tcPictures addSubview:lblPicture];
	[tcPictures addSubview:lblList];
	
	[self.view addSubview:tcPictures];
	
	currentView = vPictures;
	lblCurrent = lblPicture;
	
	[activityIndicator startAnimating];
	tvPictures.hidden = TRUE;
	
	
	lstView.view.frame = vPictures.frame;
	lstView.view.hidden = TRUE;
	[self.view addSubview:lstView.view];
}

- (void)viewDidAppear:(BOOL)animated{
	tvPictures.delegate = self;
	tvPictures.dataSource = self;
	
	[tvPictures reloadData];
	
	activityIndicator.hidden = TRUE;
	tvPictures.hidden = FALSE;
}

-(void) createFooter{
	UIFont *fnt = [UIFont fontWithName:@"Verdana" size: 10.0];
	lblPicture = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 60, 20)];
	lblList = [[UILabel alloc] initWithFrame:CGRectMake(90, 5, 70, 20)];
	
	
	lblPicture.textAlignment = UITextAlignmentCenter;
	lblList.textAlignment = UITextAlignmentCenter;
	
	[lblPicture setBackgroundColor:[UIColor darkGrayColor]];
	[lblList setBackgroundColor:[UIColor clearColor]];
	
	lblPicture.text = @"Pictures";
	lblList.text = @"List";
	
	lblPicture.font = fnt;
	lblList.font = fnt;
	
	lblPicture.textColor = [UIColor whiteColor];	
	lblList.textColor = [UIColor whiteColor];	
	
	lblPicture.userInteractionEnabled = YES;
	lblList.userInteractionEnabled = YES;
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
	NSSet *allTouches = [event allTouches];
	
	//Get the first touch.
	UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
	
	if (touch.view == lblList && currentView != lstView){
		[UIView beginAnimations:nil context:NULL];
		[UIView setAnimationDuration:0.75];
		[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:lstView.view cache:YES];
		vPictures.hidden = TRUE;
		lstView.view.hidden = FALSE;
		[UIView commitAnimations];
		
		currentView = lstView.view;
		
		[lblPicture setBackgroundColor:[UIColor clearColor]];
		[lblList setBackgroundColor:[UIColor darkGrayColor]];
	}
	
	if (touch.view == lblPicture && currentView != vPictures){
		[UIView beginAnimations:nil context:NULL];
		[UIView setAnimationDuration:0.75];
		[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:vPictures cache:YES];
		vPictures.hidden = FALSE;
		lstView.view.hidden = TRUE;
		[UIView commitAnimations];
		currentView = vPictures;
		
		[lblPicture setBackgroundColor:[UIColor darkGrayColor]];
		[lblList setBackgroundColor:[UIColor clearColor]];
	}
}
- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


#pragma mark UITableView Delegate mehods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return 145;
}

/*- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
 Album *a = [[Album alloc] initWithNibName:@"Album" bundle:[NSBundle mainBundle]];
 [self.navigationController pushViewController:a animated:YES];
 [a release];
 }*/

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	int row = indexPath.row;
	UITableViewCell *cell = [tvPictures dequeueReusableCellWithIdentifier:@"cell"];
	if (cell == nil)
	{
		cell = [[[PictureCellView alloc] initWithFrame:CGRectZero reuseIdentifier:@"cell"] autorelease];		
	}		
	return cell;
}



-(void)Back:(id)sender{
	[self.navigationController popViewControllerAnimated:YES];
}

@end
